package com.dexilaonian.adpter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.bean.OrderDetailBean;
import com.dexilaonian.utils.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2018/6/23.
 */

public class OrderDetailAdapter extends BaseAdapter{

    private Context mContext;
    private  List<OrderDetailBean> mConfirmList;

    public OrderDetailAdapter(Context context, List<OrderDetailBean> confirmList) {
        mContext = context;
        mConfirmList = confirmList;
    }



    @Override
    public int getCount() {
        if (mConfirmList.size() == 0) {
            return 0;
        } else {
            return mConfirmList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_store_detail, null);
            viewHolder.detailPic = (ImageView) convertView.findViewById(R.id.item_detail_pic);
            viewHolder.detail_title = (TextView) convertView.findViewById(R.id.item_detail_title);
            viewHolder.detail_text = (TextView) convertView.findViewById(R.id.item_detail_text);
            viewHolder.detail_price = (TextView) convertView.findViewById(R.id.item_detail_price);
            viewHolder.detail_num = (TextView) convertView.findViewById(R.id.item_detail_num);
            convertView.setTag(viewHolder);
        } else {
           viewHolder = (ViewHolder) convertView.getTag();
        }
        String picUrl = mConfirmList.get(position).getPicUrl();
        String productName = mConfirmList.get(position).getProductName();
        int productId = mConfirmList.get(position).getProductId();
        String pspec = mConfirmList.get(position).getPspec();
        int quantity = mConfirmList.get(position).getQuantity();
        double price = mConfirmList.get(position).getPrice();
        if (!TextUtils.isEmpty(picUrl)) {
            ImageLoader.display(mContext,picUrl,viewHolder.detailPic);
        }
        if (!TextUtils.isEmpty(productName)) {
            viewHolder.detail_title.setText(productName);
        }
        if (!TextUtils.isEmpty(pspec)) {
            viewHolder.detail_text.setText(pspec);
        }
        viewHolder.detail_price.setText("￥"+price);
        viewHolder.detail_num.setText("x"+quantity );
        return convertView;
    }
    class ViewHolder{
        ImageView detailPic;
        TextView detail_title;
        TextView detail_text;
        TextView detail_price;
        TextView detail_num;
    }
}
